package com.woniuxy.oldmanapi.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.oldmanapi.cvo.CareVo;
import com.woniuxy.oldmanapi.cvo.OverdueVo;
import com.woniuxy.oldmanapi.entity.Care;
import com.woniuxy.oldmanapi.mapper.CareMapper;
import com.woniuxy.oldmanapi.service.CareService;
import com.woniuxy.oldmanapi.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CareController {
    @Autowired
    CareService careService;

    //查询==查询全部或某个护理级别的明细
    @GetMapping("/care/searchList")
    public ResponseResult<List<CareVo>> list(@RequestParam(value = "careId", defaultValue = "0")int careId) {

        ResponseResult<List<CareVo>> result = new ResponseResult<>();
        try {
            List<CareVo> list = careService.findCareVoByCareId(careId);
            result.setMsg("查询成功");
            result.setCode(200);
            result.setData(list);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg("查询失败");
            result.setCode(201);

        }
        return result;
    }

    //删除
    @GetMapping("/care/remove/{id}")
    public ResponseResult<Void> removeCare(@PathVariable("id") int id) {

        ResponseResult<Void> result = new ResponseResult<>();
        try {
            careService.removeByCareId(id);
            result.setMsg("删除成功");
            result.setCode(200);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg(e.getMessage());
            result.setCode(201);

        }
        return result;
    }

    //修改
    @PostMapping("/care/modify")
    public ResponseResult<Void> modifyCare(@RequestBody CareVo careVo) {

        ResponseResult<Void> result = new ResponseResult<>();
        try {
            careService.modifyCare(careVo);
            result.setMsg("修改成功");
            result.setCode(200);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg("修改失败");
            result.setCode(201);

        }
        return result;
    }

    //添加
    @PostMapping("/care/add")
    public ResponseResult<Void> addCare(@RequestBody CareVo careVo) {

        ResponseResult<Void> result = new ResponseResult<>();
        try {
            careService.addCare(careVo);
            result.setMsg("添加成功");
            result.setCode(200);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg("添加失败");
            result.setCode(201);
        }
        return result;
    }

    @GetMapping("/care/selectAllListYsw")
    public ResponseResult<List<Care>> selectAllListYsw() {

        ResponseResult<List<Care>> result = new ResponseResult<>();
        try {
            List<Care> list = careService.selectAllListYsw();
            result.setMsg("查询成功");
            result.setCode(200);
            result.setData(list);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg("查询失败");
            result.setCode(201);
        }
        return result;
    }


    @GetMapping("/care/searchCareAll")
    public ResponseResult<List<Care>> list() {

        ResponseResult<List<Care>> result = new ResponseResult<>();
        try {
            List<Care> list = careService.findCareAll();
            result.setMsg("查询成功");
            result.setCode(200);
            result.setData(list);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg("查询失败");
            result.setCode(201);

        }
        return result;
    }

    @GetMapping("/care/searchCareVoByCid")
    public ResponseResult<CareVo> searchCarevo(@RequestParam(value = "careId", defaultValue = "0") int careId) {

        ResponseResult<CareVo> result = new ResponseResult<>();
        try {
            CareVo careVo = careService.findCareVoByCId(careId);
            result.setMsg("查询成功");
            result.setCode(200);
            result.setData(careVo);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg("查询失败");
            result.setCode(201);

        }
        return result;
    }


}
